package com.hackvan2012.controllers;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.Text;
import com.hackvan2012.datastore.AppDatastore;
import com.hackvan2012.datastore.dao.PostObject;
import com.hackvan2012.datastore.factory.DataFactory;

public class PostCommentController extends HttpServlet {
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		AppDatastore ds = new AppDatastore();
		String parentId = req.getParameter("parentId");

		String comment = req.getParameter("text");
		Text text = new Text(comment);

		PostObject newPost = DataFactory.createPost(parentId, text);

		ds.addPost(newPost);
		
		resp.sendRedirect("/viewentry");
	}
}
